def prost(x):
    for i in range(2,x):
        if x % i == 0:
            return 0
    return 1
print("Введите любое 4-хзначное натуральное число ")
s=int(input())
kol_pr=0
max_pr=0
if s>=1000 and s<10000:
    s=str(s)
    x=s[0]
    if prost(int(x))  == 1:
        kol_pr+=1
        max_pr=max(max_pr,int(x))
    x=s[1]
    if prost(int(x)):
        kol_pr+=1
        max_pr=max(max_pr,int(x))
    x=s[2]
    if prost(int(x))  == 1:
        kol_pr+=1
        max_pr=max(max_pr,int(x))
    x=s[3]
    if prost(int(x))  == 1:
        kol_pr+=1
        max_pr=max(max_pr,int(x))
    x=s[0]+s[1]
    if prost(int(x))  == 1:
        kol_pr+=1
        max_pr=max(max_pr,int(x))
    x=s[1]+s[2]
    if prost(int(x))  == 1:
        kol_pr+=1
        max_pr=max(max_pr,int(x))
    x=s[2]+s[3]
    if prost(int(x))  == 1:
          kol_pr+=1
          max_pr=max(max_pr,int(x))
    x=s[0]+s[1]
    if prost(int(x))  == 1:
          kol_pr+=1
          max_pr=max(max_pr,int(x))
    x=s[1]+s[2]
    if prost(int(x))  == 1:
          kol_pr+=1
          max_pr=max(max_pr,int(x))
    x=s[2]+s[3]
    if prost(int(x))  == 1:
          kol_pr+=1
          max_pr=max(max_pr,int(x))
    x=s[0]+s[1]+s[2]+s[3]
    if prost(int(x))  == 1:
          kol_pr+=1
          max_pr=max(max_pr,int(x))
          x=s[0]+s[1]+s[2]+s[3]
    if prost(int(x))  == 1:
         kol_pr+=1
         max_pr=max(max_pr,int(x))
    if kol_pr > 0:
         print(max_pr)
    else:
        print(0)
else:
    print(0)
    

          
    
     
          
     
      
     
     
      
          
         
     
         
         
         
     
    
    
    
        
        
    
    
        
        
